#ifndef NEWTONINTERPOLATION_HPP
#define NEWTONINTERPOLATION_HPP

#include "Function.hpp"
#include <vector>
#include <functional>

class NewtonInterpolation : public Function {
private:
    std::vector<double> x; // 插值节点的 x 坐标
    std::vector<double> y; // 插值节点的 y 坐标
    std::vector<double> z; // 插值节点的差商值

public:
    NewtonInterpolation(const std::vector<double>& x, const std::vector<double>& y);
    NewtonInterpolation(const std::vector<double>& x, std::function<double(double)> f);
    virtual ~NewtonInterpolation() {}

    double operator()(double x) const override;
    virtual double derivative(double x) const override;

    // 返回插值多项式的次数
    int getDegree() const;
};

#endif // NEWTONINTERPOLATION_HPP